package com.qf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package com.qf.controller
 * @Description: 生成验证码
 * @Date 2022/5/23 20:11
 */
@WebServlet("/code")
public class CodeController extends BaseServlet{
    /**
     * 生成验证码方法
     * */
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //1.生成验证码
        ValidateCode validateCode = new ValidateCode(100, 40, 4, 20);

        //2.获取验证码的内容
        String code = validateCode.getCode();

        //3.将验证码保存到session会话中
        request.getSession().setAttribute("code",code);

        //4.将验证码写入到前端
        validateCode.write(response.getOutputStream());
    }
}
